package pages;

import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;

import model.Film;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.Select;

public class FilmEditPage extends InternalPage {

	public FilmEditPage(PageManager pages) {
		super(pages);
	}



	@FindBy(name = "imdbid")
	private WebElement imdbidField;

	@FindBy (name="name")
	private WebElement titleField;

	@FindBy (name="aka")
	private WebElement akaField;

	@FindBy (name="year")
	private WebElement yearField;

	@FindBy (name="notes")
	private WebElement notesField;

	@FindBy (name="duration")
	private WebElement durationField;

	@FindBy (name="rating")
	private WebElement ratingField;

	@FindBy (id="own_no")
	private WebElement ownNoRadio;

	@FindBy (id="own_yes")
	private WebElement ownYesRadio;

	@FindBy (id="seen_no")
	private WebElement seenNoRadio;

	@FindBy (id="seen_yes")
	private WebElement seenYesRadio;

	@FindBy (id="loaned_no")
	private WebElement loanedNoRadio;

	@FindBy (id="loaned_yes")
	private WebElement loanedYesRadio;

	@FindBy (id="submit")
	private WebElement submitBtn;


	 public FilmEditPage setImdbid(String text) {
		 imdbidField.sendKeys(text);
		    return this;
		 }

		public FilmEditPage setTitle(String title) {
			titleField.sendKeys(title);
			return this;

		}

		public FilmEditPage setAKA(String aka) {
			akaField.sendKeys(aka);
			return this;
		}

		public FilmEditPage setYear(String year) {
			yearField.sendKeys(year);
			return this;
		}

		public FilmEditPage setNotes(String notes) {
			notesField.clear();
			notesField.sendKeys(notes);
			return this;
		}

		public FilmEditPage setDuration(String duration) {
			durationField.clear();
			durationField.sendKeys(duration);
			return this;
		}

		public FilmEditPage setRating(String rating) {
			ratingField.clear();
			ratingField.sendKeys(rating);
			return this;
		}


		public FilmEditPage setIsOwned(boolean isOwned) {
			if (isOwned)
				ownYesRadio.click();
			else
				ownNoRadio.click();
			return this;
		}

		public FilmEditPage setIsSeen(boolean isSeen) {
			if (isSeen)
				seenYesRadio.click();
			else
				seenNoRadio.click();
			return this;
		}

		public FilmEditPage setIsLoaned(boolean isLoaned) {
			if (isLoaned)
				loanedYesRadio.click();
			else
				loanedNoRadio.click();
			return this;
		}

		public void save(){
			submitBtn.click();
		}

	public FilmEditPage ensurePageLoaded() {
	    super.ensurePageLoaded();
	    wait.until(presenceOfElementLocated(By.name("imdbid")));
	    return this;
	  }







}